package logic

import (
	"context"
	"furni-suite/furnirpc/furnirpc"
	"furni-suite/furnirpc/internal/svc"
	"furni-suite/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserCreateLogic {
	return &UserCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户注册
func (l *UserCreateLogic) UserCreate(in *furnirpc.UserCreateRequest) (*furnirpc.UserCreateResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.User{
		Username: in.UserName,
		Password: in.Password,
	}

	if err := user.UserCreate(mysql.DB); err != nil {
		return nil, err
	}
	return &furnirpc.UserCreateResponse{
		UserId: int64(user.ID),
	}, nil
}
